package com.star.security;

import com.star.util.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 密码处理
 *
 * @author tanyapeng
 * @date 2021/3/7
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

     public DefaultPasswordEncoder() {
     this(-1);
     }
     public DefaultPasswordEncoder(int strength) {
     }

     /**
     * 进行MD5加密
     *
     * @param charSequence
     * @return
     */
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }

    /**
     * 进行密码比对
     *
     * @param charSequence
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(charSequence.toString()));
    }
}
